<!DOCTYPE html>
<html>

    <head>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1" />
        <meta charset="UTF-8">
        <title>{$site_info.site_name|default=''}</title>
        <meta name="keywords" content="{$site_info.site_seo_keywords|default=''}"/>
        <meta name="description" content="{$site_info.site_seo_description|default=''}">
        <include file="public@head"/>
        <link rel="stylesheet" href="__TMPL__/public/assets/css/mobiscroll.css" />
        <link rel="stylesheet" href="__TMPL__/public/assets/css/mobiscroll_002.css" />
        <link rel="stylesheet" href="__TMPL__/public/assets/css/mobiscroll_003.css" />
    </head>
    <body>
		
		<div class="repairs room">
			
			<!--头部-->
			<div class="top" style="background: url({:cmf_get_image_url($img['img'])}) no-repeat;background-size: 100% 100%;">
                <if condition="$user_type eq 'fix_admin'">
				<p>报修广场</p>
                <elseif condition="$user_type eq 'fix'"/>
                <p>我的报修单</p>
                <else/>
                <p>我的报修</p>
                </if>
			</div>

            <if condition="$user_type eq 'fix_admin'">
            <form action="{:cmf_url('repair/list/myRepair')}" method="post" id="sle_form">
            <input type="hidden" name="repair_status" id="repair_status" value="{$repair_status.id}">
            <div class="pTop">
                <label>时间：</label>
                <div class="input">
                    <input value="{$appDate.year}" class="" readonly="readonly" name="appDate" id="appDate" type="text">
                    <p id="appDateText">{$appDate.day}<span>周{$appDate.week}</span></p>
                </div> <span>-</span>
                <div class="input">
                    <input value="" class="" readonly="readonly" name="appStatus" id="amOrpm" type="text">
                    <p id="amOrpmText"><if condition="$repair_status.name">{$repair_status.name}<else/>请选择</if></p>
                </div>
                <ul id="sex-list" style="display: none">
                    <li data-id="-1">请选择</li>
                    <foreach name="search_status" item="vo" key="k">
                    <li data-id="{$k}">{$vo}</li>
                    </foreach>
                </ul>
            </div>
            </form>
            </if>
			
			<div class="repairdCn">
				<div class="listsBox">
					<foreach name="lists" item="vo">
					<div class="rpList">
						<a href="{:cmf_url('repair/list/repair_detail',array('id'=>$vo['id']))}">
						<div class="rpTop div_float bigTop">
							<p class="rpTil eli_one"><span></span>{$vo.post_title}</p>
                            <if condition="$user_type eq 'fix'">
                            <p class="edit blueT">{$vo.repair_status_text}</p>
                            <elseif condition="$vo.repair_status neq 3">
							<p class="edit blueT">{$vo.repair_status_text}</p>
                            </if>
						</div>
						<div class="rpBtm">
							<div class="div_float">
								<p class="eli_one">类型 ：{$vo.category_info.name}</p>
								<p class="eli_one">{$vo.member_info.department}  / {$vo.member_info.user_login}</p>
								<p class="eli_one">地点：{$vo.repair_place}</p>
							</div>
						</div>
                        <!-- 如果不是维修人员则显示 -->
						<if condition="$vo.repairman_info and $vo.user_type neq 'fix'">
						<div class="person div_float">
							<p class="l">维修人员：{$vo.repairman_info.user_login}</p>
							<if condition="$vo.repair_status eq 3"><p class="pState <if condition="$vo.repair_status neq 3">blueT</if>">{$vo.repair_status_text}</p></if>
						</div>
						</if>
						</a>
					</div>
					</foreach>
				</div>
			</div>
			
			<!--公共底部-->
			<include file='public@footer'/>
			
		</div>
		
	</body>
	<include file='public@scripts'/>
    <script type="text/javascript" src="__TMPL__/public/assets/js/mobiscroll.custom-2.5.2.min.js" ></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/mobiscroll_003.js" ></script>
</html>

<script type="text/javascript">
$(function(){
    var counter = 1;
    // 每页展示4个
    var num = 5;
    var pageStart = 0,pageEnd = 0;
    var repair_status = $('#repair_status').val();
    var appDate = $('#appDate').val();

    // dropload
    $('.repairdCn').dropload({
        scrollArea : window,
        domDown : {
            domClass   : 'dropload-down',
            domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData  : '<div class="dropload-noData">没有更多内容了</div>'
        },
        loadDownFn : function(me){
            $.ajax({
                type: 'POST',
                url: '{:cmf_url("/repair/List/listAjax")}',
                data: {start:pageStart,size:num,repair_status:repair_status,appDate:appDate},
                dataType: 'json',
                success: function(data){
                    var data_num = data.length;
                    var result = '';
                    var stutas_one = '';
                    counter++;

                    if(data_num<=num){
                       $(".dropload-down").hide();
                       $('.listsBox').append('<div class="norecode">没有更多内容了</div>');
                    }else{
                       $(".dropload-load").show();

                        pageEnd = num * counter;
                        pageStart = pageEnd - num;

                        for(var i = pageStart; i < pageEnd; i++){
                            var repairman = '';
                        	if (data[i].repairman_info != null && data[i].user_type != 'fix') {
                        		repairman += '<div class="person div_float">'
    											+'<p class="l">维修人员：'+data[i].repairman_info.user_login+'</p>'
    											+'<p class="pState">'+data[i].repair_status_text+'</p>'
    									    +'</div>'
                        	}else{
                        		// stutas_one = data[i].repair_status_text;
                        		repairman = '';
                        	}

    						result += '<div class="rpList">'
    									+'<a href="{:cmf_url("/repair/List/repair_detail/id/'+data[i].id+'")}">'
    									+'<div class="rpTop div_float bigTop">'
    										+'<p class="rpTil eli_one"><span></span>'+data[i].post_title+'</p>'
    										+'<p class="edit blueT">'+data[i].repair_status_text+'</p>'
    									+'</div>'
    									+'<div class="rpBtm">'
    										+'<div class="div_float">'
    											+'<p>类型 ：'+data[i].category_info.name+'</p>'
    											+'<p>'+data[i].member_info.department+'  / '+data[i].member_info.user_login+'</p>'
    											+'<p>地点：'+data[i].repair_place+'</p>'
    										+'</div>'
    									+'</div>'
    									+repairman
    									+'</a>'
    								 +'</div>';

                            if((i + 1) >= data.length){
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                                break;
                            }
                        }
                        // 为了测试，延迟1秒加载
                        setTimeout(function(){
                            $('.listsBox').append(result);
                            // 每次数据加载完，必须重置
                            me.resetload();
                        },1000);
                    }
                },
                error: function(xhr, type){
                    alert('加载失败!');
                    // 即使加载出错，也得重置
                    me.resetload();
                }
            });
        },
        threshold : 50
    });
    
});
</script>

<script>
    $(function(){
        $("#appDate").mobiscroll().date({
            theme: "android-ics",
            lang: "zh",
            display: 'bottom',
            selectType: 'week',
            dateFormat: 'yy-mm-dd', //返回结果格式化为年月格式
            //wheels:[], //设置此属性可以只显示年月，此处演示，就用下面的onBeforeShow方法,另外也可以用treelist去实现
            //onBeforeShow: function (inst) { inst.settings.wheels[0].length>2?inst.settings.wheels[0].pop():null; }, //弹掉“日”滚轮
            headerText: function(valueText) { //自定义弹出框头部格式
                array = valueText.split('-');
                return array[0] + "年" + array[1] + "月" + array[2] + "日";
            },
            onSelect: function(valueText, inst) {
                var showDay = valueText.split('-');
                var mydate=new Date(valueText);
                var myddy=mydate.getDay();//获取存储当前日期
                var weekday=["周日","周一","周二","周三","周四","周五","周六"];
                $("#appDateText").html(showDay[1]+'-'+showDay[2]+'<span>'+weekday[myddy]+'</span>');
                $('#sle_form').submit();
            }
        });

        $("#amOrpm").click(function() {
            var that = this;
            $("#sex-list").mobiscroll().treelist({
                theme: "android-ics",
                lang: "zh",
                display: 'bottom',
                headerText: '请您选择',
                onSelect: function(valueText) {
                    var m = $(this).find("li").eq(valueText).html();
                    var id = $(this).find("li").eq(valueText).attr('data-id');
                    $(that).val(m);
                    $('#amOrpmText').html(m)
                    $('#repair_status').val(id);
                    $('#sle_form').submit();
                }
            });
            $("input[id^=sex-list]").focus();
        });
    })
</script>
